﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Text;
using OSGeo.MapGuide;

namespace IGIS.Core
{
    public static class ResourceHelper
    {
        // Methods
        public static XmlDocument GetResourceXml(HtzMgHelper helper, MgResourceIdentifier resourceId)
        {
            XmlDocument result = new XmlDocument();
            if (resourceId != null)
            {
                result.LoadXml(helper.ResourceService.GetResourceContent(resourceId).ToString());
            }
            return result;
        }

        public static void SetResourceFromXml(HtzMgHelper helper, MgResourceIdentifier resourceId, XmlDocument doc)
        {
            byte[] layerDef = new UTF8Encoding().GetBytes(doc.InnerXml);
            MgByteSource byteSource = new MgByteSource(layerDef, layerDef.Length);
            byteSource.SetMimeType("text/xml");
            helper.ResourceService.SetResource(resourceId, byteSource.GetReader(), null);
        }
    }

 

}